package com.lion.tag.head;

import java.io.IOException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.PageContext;
import javax.servlet.jsp.tagext.SimpleTagSupport;

public class Head extends SimpleTagSupport {
	private String easyui;
	private String charset;
	
	public HttpServletRequest getRequest(){
		HttpServletRequest request = (HttpServletRequest)((PageContext)this.getJspContext()).getRequest();
		return request;
	}
	
	public String contextPath(){
		return getRequest().getContextPath();
	}

	/**
	 * 实现引入js、css依赖库
	 */
	@Override
	public void doTag() throws JspException, IOException {
		JspWriter out = getJspContext().getOut();
		String ctx = contextPath();
		StringBuilder sb = new StringBuilder(400);
		sb.append("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=").append(charset).append("\" />\n");
		sb.append("<meta http-equiv=\"pragma\" content=\"no-cache\">\n");
		sb.append("<meta http-equiv=\"cache-control\" content=\"no-cache\">\n");
		sb.append("<meta http-equiv=\"expires\" content=\"0\">\n");
		sb.append("<link rel=\"stylesheet\" type=\"text/css\" href=\"").append(ctx).append("/").append(easyui).append("/themes/default/easyui.css\"/>\n");
		sb.append("<link rel=\"stylesheet\" type=\"text/css\" href=\"").append(ctx).append("/").append(easyui).append("/themes/icon.css\"/>\n");
		sb.append("<link rel=\"stylesheet\" type=\"text/css\" href=\"").append(ctx).append("/").append(easyui).append("/themes/iconExtension.css\">\n");
		sb.append("<link rel=\"stylesheet\" type=\"text/css\" href=\"").append(ctx).append("/").append(easyui).append("/images/lion.css\"/>\n");
		sb.append("<script type=\"text/javascript\" src=\"").append(ctx).append("/").append(easyui).append("/jquery.min.js\"></script>\n");
		sb.append("<script type=\"text/javascript\" src=\"").append(ctx).append("/").append(easyui).append("/jquery.easyui.min.js\"></script>\n");
		sb.append("<script type=\"text/javascript\" src=\"").append(ctx).append("/").append(easyui).append("/locale/easyui-lang-zh_CN.js\"></script>\n");
		sb.append("<script type=\"text/javascript\" src=\"").append(ctx).append("/").append(easyui).append("/images/lion.js\"></script>\n");
		out.write(sb.toString());
	}

	public String getEasyui() {
		return easyui;
	}

	public void setEasyui(String easyui) {
		this.easyui = easyui;
	}

	public String getCharset() {
		return charset;
	}

	public void setCharset(String charset) {
		this.charset = charset;
	}


}
